<?php

namespace IDock\Insurance\ACIC\Request;

use Exception;
use IDock\Common\Tools\XMLTools;
use IDock\Insurance\ACIC\Bean\CancelInfo;
use IDock\Insurance\ACIC\Response\CancelInsuranceResponse;

class CancelInsuranceRequest extends AllACICRequest
{
    protected $code = 'V21';

    protected $response = CancelInsuranceResponse::class;

    protected $logTip = '投保注销';

    private $orgCode = '';

    private $cancelInfos = [];

    /**
     * @return array
     * @throws Exception
     */
    public function generate(): array
    {
        $param = [
            'OrgCode' => $this->orgCode,
            'CancelInfos' => $this->cancelInfos,
        ];
        $applicationXML = '';
        foreach ($param['CancelInfos'] as $val) {
            $val = json_decode(json_encode($val), true);
            $applicationXML .= "<CancelInfo>" . XMLTools::ToXML($val, '', '') . "</CancelInfo>";
        }
        $param['CancelInfos'] = $applicationXML;
        return $param;
    }

    /**
     * @param string $orgCode
     */
    public function setOrgCode(string $orgCode): void
    {
        $this->orgCode = $orgCode;
    }

    /**
     * @param CancelInfo $cancelInfo
     */
    public function appendCancelInfos(CancelInfo $cancelInfo): void
    {
        $this->cancelInfos[] = $cancelInfo;
    }


}